import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

public class Demo05 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Callable<Integer> integerCallable = new Callable<>() {
            @Override
            public Integer call() throws Exception {
                int sum = 0;
                for (int i = 1; i <= 1000; i++) {
                    sum += i;
                }
                return sum;
            }
        };
        FutureTask<Integer> integerFutureTask = new FutureTask<>(integerCallable);
        Thread thread = new Thread(integerFutureTask);
        thread.start();
        Integer result = integerFutureTask.get();
        System.out.println(result);
    }
}
